Create custom action msg
Table of Content
Actions are defined as .action file locate in action sub folder
The best practice is to create a package dedicated to ROS2 custom messages.
The package type is cmake_ament and
naming the package with _interface suffix so it’ clear that the package is an interface package.
ros2 pkg create custom_interfaces
rm -rf include
rm -rf src
mkdir msg srv action
- Remove from the package the
srcandincludefolders - Create folders for
msg,srv,actionsub folders/ - Add
action filefor example name itCounter.action - Action files defined in this structure
# Request
---
# Result
---
# Feedback
Action Definition#
action/Counter.action
int32 count
---
int32 total
---
int32 current
CMakeLists#
CMakeList.txt
cmake_minimum_required(VERSION 3.8)
project(action_tutorial_interfaces)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}
"action/MyAction.action"
)
ament_export_dependencies(rosidl_default_runtime)
ament_package()
CMakeLists
Keep each action,srv or msg in new line
Package.xml#
Add to package.xml
<buildtool_depend>rosidl_default_generators</buildtool_depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<member_of_group>rosidl_interface_packages</member_of_group>
build and test#
build#
colcon build --packages-select action_tutorial_interfaces
test#
ros2 interface list | grep Counter
check
ros2 interface show custom_interfaces/action/Counter
#
int32 count
---
int32 total
---
int32 current